package com.gitee.wsl.unit.time

import com.gitee.wsl.unit.SubBaseUnit
import com.gitee.wsl.unit.UnitType


sealed interface TimeUnitType: UnitType<Float> {

    // 纳秒
    //NANOS("Nanos", Duration.ofNanos(1)),
    data object NANOS: TimeUnitType {
        override val baseUnit: Float = MICROS.baseUnit*0.001f
    }

    // 微秒
    //MICROS("Micros", Duration.ofNanos(1000)),
    data object MICROS: TimeUnitType {
        override val baseUnit: Float = 0.001f
    }
     // 毫秒
    //MILLIS("Millis", Duration.ofNanos(1000_000)),
     data object MILLIS: TimeUnitType {
        override val baseUnit: Float = 1f
    }

    // 秒与毫秒的倍数
    data object SECOND: TimeUnitType {
        override val baseUnit: Float = 1000f
    }

    // 分与毫秒的倍数
    data object MINUTE : TimeUnitType {
        override val baseUnit: Float = SECOND.baseUnit*60
    }

    // 时与毫秒的倍数
    data object HOUR : TimeUnitType {
        override val baseUnit: Float = MINUTE.baseUnit*60
    }

    // 天与毫秒的倍数
    data object DAY : TimeUnitType {
        override val baseUnit: Float = HOUR.baseUnit*24
    }

    // 周与毫秒的倍数
    data object WEEK : TimeUnitType {
        override val baseUnit: Float = DAY.baseUnit*7
    }

    // 月与毫秒的倍数
    data object MONTH : TimeUnitType {
        override val baseUnit: Float = DAY.baseUnit*30
    }

    // 年与毫秒的倍数
    data object YEAR : TimeUnitType {
        override val baseUnit: Float = DAY.baseUnit*365
    }

    // 十年
    //DECADES("Decades", Duration.ofSeconds(31556952L * 10L)),
    data object DECADES : TimeUnitType {
        override val baseUnit: Float = YEAR.baseUnit*10
    }
    /*// 世纪（即百年）
    CENTURIES("Centuries", Duration.ofSeconds(31556952L * 100L)),
    // 千年
    MILLENNIA("Millennia", Duration.ofSeconds(31556952L * 1000L)),
    // 十亿年
    ERAS("Eras", Duration.ofSeconds(31556952L * 1000_000_000L)),*/

}

sealed class TimeUt<SUB: SubBaseUnit<Float, TimeUnitType, *>>(
    value:Float,
    type: TimeUnitType,
    bUnitValue:SUB?=null
): SubBaseUnit<Float, TimeUnitType, SUB>(value, type, bUnitValue) {

    override fun toBase(): Float {
        TODO()
        //return value * type.baseUnit + bUnitValue.ifNullValue(0, bUnitValue!!.toBase())
    }

     override fun format(): String {
         TODO("Not yet implemented")
     }


     companion object{
        fun generate(value: Float): TimeUt<*> {
             TODO()
        }
    }
}

infix fun TimeUt<*>.plus(other: TimeUt<*>): TimeUt<*> {
    val new = this.toBase()+other.toBase()
    return TimeUt.generate(new)
}

infix fun TimeUt<*>.minus(other: TimeUt<*>): TimeUt<*> {
    val new = this.toBase()-other.toBase()
    return TimeUt.generate(new)
}

